def is_prime(n):
    for i in range(2, int(n**0.5) + 1):
        if n % i == 0:
            return False
    return True

def find_prime(num):
    num_str = str(num)
    largest_prime = 0
    for i in range(len(num_str)):
        for j in range(i + 1, len(num_str) + 1):
            sub_num = int(num_str[i:j])
            if is_prime(sub_num) and sub_num > largest_prime:
                largest_prime = sub_num
    return largest_prime

num = int(input())
if 1000 <= num <= 9999:
    result = find_prime(num)
else:
    result = 0
print(result)